import { reactive } from "vue";
import { useUser } from "@/stores/user";
import { setTotalEnergy } from "./checkin";
import { formatEnergy } from "@/comm/energy";
const user = useUser();
const energy = reactive<EnergyType>({
    totalInvites: 0,
    totalEnergy: 0,
    todayEnergy: 0,
    totalLuckEnergy: 0,
    todayLuckEnergy: 0,
    getuserEnergyCount: async function () {
        console.warn("========= getuserEnergyCount")
        const data: EnergyCount = await user.getuserEnergyCount<EnergyCount>();
        if (data !== undefined) {
            this.totalInvites = data.totalInvites;
            this.totalEnergy = formatEnergy(data.totalEnergy);
            this.todayEnergy = formatEnergy(data.todayEnergy);
            this.totalLuckEnergy = formatEnergy(data.totalLuckEnergy);
            this.todayLuckEnergy = formatEnergy(data.todayLuckEnergy);
            setTotalEnergy(formatEnergy(data.signEnergy));
        }
        return data;
    }
});

export { energy };

type EnergyType = {
    totalInvites: number;
    totalEnergy: number;
    todayEnergy: number;
    totalLuckEnergy: number;
    todayLuckEnergy: number;
    getuserEnergyCount: () => void;
}

type EnergyCount = {
    totalInvites: number;
    totalEnergy: number;
    todayEnergy: number;
    totalLuckEnergy: number;
    todayLuckEnergy: number;
    signEnergy: number;
}
